function addUpdateAddress() {
	var listDiv = $("#list");
	var formDiv = $("#addupdate");
	var errorMsg = $("#error_message");
	var name = $("#name").val();
	var mobile = $("#mobile").val();
	var province = $("#cmbProvince").val();
	var city = $("#cmbCity").val();
	var district = $("#cmbArea").val();
	var detail = $("#detail").val();

	if (name.length == 0) {
		errorMsg.html("收货人姓名不能为空");
		return;
	}
	if (mobile.length == 0) {
		errorMsg.html("收货人手机号不能为空");
		return;
	}
	if (detail.length == 0) {
		errorMsg.html("详细地址不能为空");
		return;
	}


	$.ajax({
		type : 'POST',
		url : ctx + '/address/addUpdateAddress.do',
		data : {
			name : name,
			mobile : mobile,
			province : province,
			city : city,
			district : district,
			detail : detail
		},
		dataType : 'json',
		timeout : 30000,
		context : $('body'),
		success : function(data) {
			if (data.code == "ok") {
				var object = data.object;
				$("#name").val(object.name);
				$("#mobile").val(object.mobile);
				$("#cmbProvince").val(object.province);
				$("#cmbCity").val(object.city);
				$("#cmbArea").val(object.district);
				$("#detail").val(object.detail);
				
				var html = 	'<ul class="list-group">'
							+'<li class="list-group-item">收货人：'+object.name+'</li>'
							+'<li class="list-group-item">手机号：'+object.mobile+'</li>'
							+'<li class="list-group-item">所在地区：'+object.province+object.city+object.district+'</li>'
							+'<li class="list-group-item">详细地址：'+object.detail+'</li>'
							+'</ul>'
							+'<button type="button"  onclick="update()" class="btn btn-default">修改</button>';
				listDiv.html(html);
			} else {
				errorMsg.html(data.msg);
			}
		},
		error : function(xhr, type) {
			errorMsg.html('提交失败!');
		}
	});
}

function update(){
	var listDiv = $("#list");
	var name = $("#nameHide").val();
	var mobile = $("#mobileHide").val();
	var detail = $("#detailHide").val();
	
	var html = 	'<div class="form-group">'+
					'<label for="name">收货人</label>'+
					'<input type="text"	class="form-control" id="name" value="'+name+'" />'+
				'</div>'+
				'<div class="form-group">'+
					'<label for="mobile">手机号</label>'+ 
					'<input type="text"	class="form-control" id="mobile" value="'+mobile+'" />'+
				'</div>'+
				'<div class="form-group">'+
					'<p>'+
						'<label for="district">所在地区</label>'+
					'</p>'+
					'<select id="cmbProvince" name="cmbProvince"></select>'+ 
					'<select id="cmbCity" name="cmbCity"></select>'+ 
					'<select id="cmbArea" name="cmbArea"></select>'+
				'</div>'+
				'<div class="form-group">'+
					'<label for="detail">详细地址</label>'+ 
					'<input type="text" class="form-control" id="detail" value="'+detail+'" />'+
				'</div>'+
				'<button type="button" onclick="addUpdateAddress()" class="btn btn-default">保存设置</button>'+
				'<span id="error_message"></span>';
	listDiv.html(html);
	addressInit('cmbProvince', 'cmbCity', 'cmbArea');
}
